function Node(value, node = null) {
    this.value = value
    this.next = node
}

function Queue() {
    this.init()
}

// 初始化空队列
Queue.prototype.init = function () {
    let head = new Node(0)
    this.front = head
    this.rear = head
}

// 判断队列是否为空
Queue.prototype.isEmpty = function () {
    return this.front = this.rear
}

// 入队操作
Queue.prototype.enqueue = function (value) {
    let node = new Node(value)
    this.rear.next = node
    this.rear = node
}

// 出队操作
Queue.prototype.dequeueu = function () {
    if (this.isEmpty()) {
        throw new Error('Queue is Empty')
    } else {
        let node = this.front.next
        this.front.next = node.next
        if (this.rear === node) {
            this.rear = this.front
        }
        return node.value
    }
}

// 获取队头元素
Queue.prototype.frontValue = function () {
    if (this.isEmpty()) {
        throw new Error('Queue is Empty')
    } else {
        return this.front.next.value
    }
}

// 获取队尾元素
Queue.prototype.rearValue = function () {
    if (this.isEmpty()) {
        throw new Error('Queue is Empty')
    } else {
        return this.rear.value
    }
}
